import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import UnitStateUtil from '@/UnitStateUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import SLKCommon from 'code/Core/Common/SLKCommon';
import SelectCommon from 'code/Core/Common/SelectCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 生命之力
 */
export default class DLY_PowerOfLife extends AbilityBase {
    static instance: DLY_PowerOfLife;
    buffType: AppBuffType = {
        id: 'buff_DLY_PowerOfLife',
        art: this.art,
        name: this.abilityName,
        ubertip: '增加你的治疗能力与持续伤害能力',
        dur: 12,
        stackCountMax: -1,
        attribute: {
            治疗增强: 0.1,
            持续伤害增强: 0.05,
        },
        targetAttach: 'origin',
        targetArt: 'Abilities\\Spells\\NightElf\\Tranquility\\Tranquility.mdl',
        interval: 1,
        onInterval: this.onBuffInterval.bind(this),
        onDestroy: this.onBuffDestroy.bind(this),
    };
    effctBuffType: AppBuffType = {
        id: 'buff_DLY_PowerOfLife_effect',
        art: this.art,
        name: this.abilityName,
        ubertip: this.ubertip,
        dur: 2,
        targetAttach: 'overhead',
        targetArt: 'Abilities\\Spells\\NightElf\\Tranquility\\TranquilityTarget.mdl',
        interval: 1,
        onInterval: this.effectInterval.bind(this),
        class: '光环',
    };
    onBuffDestroy(buff: Buff) {
        let model = SLKCommon.getUnitModel(buff.getParent());
        DzSetUnitModel(buff.getParent(), model);
    }
    effectInterval(buff: Buff) {
        let source = buff.getCaster();
        let lv = this.getAbilityLevel(source);
        let r = 0.01 + 0.005 * lv;
        let add = UnitCommon.取法强(source) * 0.2 * lv;
        DamageSystemInstance.applyHeal(buff.getParent(), source, UnitStateUtil.getMaxLife(buff.getParent()) * r + add, this.id);
    }
    onBuffInterval(buff: Buff) {
        // 每秒回复周围600范围内 法强 * 0.2 + (1% + 0.5%  * lv 生命) , 自身双倍
        let source = buff.getCaster();
        let lv = this.getAbilityLevel(source);
        let r = 0.01 + 0.005 * lv;
        let add = UnitCommon.取法强(source) * 0.2 * lv;
        // 自身的恢复
        DamageSystemInstance.applyHeal(source, source, (UnitStateUtil.getMaxLife(source) * r + add) * 2, this.id);
        // 友军的恢复
        let es = SelectCommon.getAllyUnitInRangeExcludeCenterUnit(source, 600);
        for (let e of es) {
            BuffCommon.addBuff({
                target: e,
                caster: source,
                ablityId: this.id,
                buffTypeId: this.effctBuffType.id,
            });
        }
    }
    constructor(id: string) {
        super(id);
        DLY_PowerOfLife.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
        BuffUtil.registerBuffType(this.effctBuffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        DzSetUnitModel(source, 'buildings\\nightelf\\AncientProtector\\AncientProtector.mdx');
        BuffCommon.addBuff({
            target: source,
            caster: source,
            buffTypeId: this.buffType.id,
            ablityId: this.id,
            config: {
                stack: this.getAbilityLevel(source),
            },
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
